<template>
	<view class="wrapper">
		<scroll-view scroll-x class="bg-white nav">
			<view class="flex text-center">
				<view aria-role="menuitem" class="cu-item flex-sub" :class="item.id==TabCur?'text-blue cur':''" v-for="(item,index) in tabList" :key="index"
				 @tap="tabSelect" :data-id="item.id">
					{{item.tabName}}
				</view>
			</view>
		</scroll-view>
		
		<view aria-role="link" class="cu-list menu card-menu margin-top shadow-lg radius" v-for="(item,index) in orditem" :key="index" @tap="toRecording(item.id)">
			<view class="cu-item arrow">
				<view class="content" bindtap="CopyLink">
					<view style="display: contents;" class="text-blue">
						<icon class="iconfont icon-kunnanbangfu1"></icon>
					</view>
					<text class="text-wight">{{item.appName}}</text>
				</view>
			</view>
			<view class="cu-item">
				<text class="text-grey">{{item.rateTime}}</text>
				<text :class="item.state == '1'?'text-yellow':'text-green'">{{item.stateVal}}</text>
			</view>
		</view>
		<view v-if="orditem.length <=0" class="text-center text-gray" style="margin-top: 360rpx;">
			<text class="iconfont icon-zanwushuju" style="font-size: 200rpx;"></text>
			<br>
			<text>暂无服务记录</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TabCur: 2,
				tabList: [
					{
						id: 2,
						tabName: '全部'
					},
					{
						id: 0,
						tabName: '进行中'
					},
					{
						id: 1,
						tabName: '已完成'
					}
				],
				paramas:{
					limit: 15,
					pageno: 1,
					codex: {}
				},
				orditem:[],
				copyList: [],
				userId:'',
			}
		},
		onLoad(){
			let userId= uni.getStorageSync('users').uid;
			this.ordData(userId);
		},
		methods: {
			ordData(userId){
				let codex = {
					"userId": userId
				}
				this.paramas.codex = codex;
				this.$request.postJson('/view/trade/page',this.paramas).then(
					res => {
						let list = res.data.rows;
						list.forEach(item => {
							if (item.state == 1) {
								item['stateVal'] = '完成'
							}else if(item.state == 0){
								item['stateVal'] = '进行中'
							}
						})
						this.copyList = list
						this.orditem=list;
					},
					err => {
						console.log("失败")
					}
				)
			},
			tabSelect(e) {
				let index = e.currentTarget.dataset.id;
				this.TabCur = index
				this.orditem = this.copyList.filter (item => {
					if (this.TabCur === 2) {
						return true
					}
					return item.state == index
				})
			},
			toRecording(id){
				uni.navigateTo({url: `/pages_mine/trade/ord-view?id=${id}`});
			}
		}
	}
</script>

<style>
.text-wight {
	font-size: 15px;
	font-weight: 600;
}
</style>
